'use strict';

const db = uniCloud.database()
exports.main = async (event, context) => {

	const {
		name,
		page = 1,
		pageSize = 10
	} = event;

	let matchObj = {}
	if (name !== '全部' && name !== '') {
		matchObj = {
			classify: name
		}
	}

	// 聚合操作
	const list = await db.collection('BOSS_job')
		.aggregate()
		.match(matchObj)
		.project({
			//不返回context字段
			context: 0 
		})
		// 要跳过多少数据
		.skip(pageSize * (page-1)) 
		.limit(pageSize)
		.end()


	// const list = await db.collection('BOSS_job')
	// .field({
	// 	context: false
	// })
	// .get()

	//返回数据给客户端
	return {
		code: 200,
		msg: '数据请求成功',
		data: list.data
	}
};